<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="表类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tableType']" placeholder="请输入表类型"></a-input>
        </a-form-item>
        <a-form-item label="表名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tableName']" placeholder="请输入表名"></a-input>
        </a-form-item>
        <a-form-item label="检查日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择检查日期" v-decorator="['inspectionDate']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="线别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['lineType']" :trigger-change="true" dictCode="mgroup_code" placeholder="请选择线别"/>
        </a-form-item>
        <a-form-item label="设备名称/检查项目" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['equipmentName']" placeholder="请输入设备名称/检查项目"></a-input>
        </a-form-item>
        <a-form-item label="设备型号/检查位置" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['equipmentModel']" placeholder="请输入设备型号/检查位置"></a-input>
        </a-form-item>
        <a-form-item label="购置日期/启动检查时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择购置日期/启动检查时间" v-decorator="['datePurchase']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="文件编号/资产编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['documentNumber']" placeholder="请输入文件编号/资产编码"></a-input>
        </a-form-item>
        <a-form-item label="检查方法" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inspectionMethod']" placeholder="请输入检查方法"></a-input>
        </a-form-item>
        <a-form-item label="检查周期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inspectionCycle']" placeholder="请输入检查周期"></a-input>
        </a-form-item>
        <a-form-item label="计入方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['accountingMethod']" placeholder="请输入计入方式"></a-input>
        </a-form-item>
        <a-form-item label="注意事项" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['beCareful']" placeholder="请输入注意事项"></a-input>
        </a-form-item>
        <a-form-item label="设备SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['equipmentSn']" placeholder="请输入设备SN"></a-input>
        </a-form-item>
        <a-form-item label="表类型编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['tableTypeCode']" :trigger-change="true" dictCode="facility_temp_type" placeholder="请选择表类型编码"/>
        </a-form-item>
        <a-form-item label="表名称编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['tableNameCode']" :trigger-change="true" dictCode="facility_name_temp" placeholder="请选择表名称编码"/>
        </a-form-item>
        <a-form-item label="保养人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maintainer']" placeholder="请输入保养人"></a-input>
        </a-form-item>
        <a-form-item label="稽查人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['reviewer']" placeholder="请输入稽查人"></a-input>
        </a-form-item>
        <a-form-item label="备用1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query1']" placeholder="请输入备用1"></a-input>
        </a-form-item>
        <a-form-item label="备用2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query2']" placeholder="请输入备用2"></a-input>
        </a-form-item>
        <a-form-item label="备用3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['query3']" placeholder="请输入备用3"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "MesMaintenanceRecordMainModal",
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/produce/mesMaintenanceRecordMain/add",
          edit: "/produce/mesMaintenanceRecordMain/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'tableType','tableName','inspectionDate','lineType','equipmentName','equipmentModel','datePurchase','documentNumber','inspectionMethod','inspectionCycle','accountingMethod','beCareful','equipmentSn','tableTypeCode','tableNameCode','maintainer','reviewer','query1','query2','query3'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'tableType','tableName','inspectionDate','lineType','equipmentName','equipmentModel','datePurchase','documentNumber','inspectionMethod','inspectionCycle','accountingMethod','beCareful','equipmentSn','tableTypeCode','tableNameCode','maintainer','reviewer','query1','query2','query3'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>